package com.dreamer.service.lottery;

import com.dreamer.domain.lottery.Lottery;
import com.dreamer.domain.lottery.vo.UserVo;
import com.dreamer.repository.lottery.LotteryDAO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ps.mx.otter.utils.SearchParameter;

import java.util.List;

@Service
public class LotteryHandler {

    @Autowired
    private LotteryDAO lotteryDAO;

    @Transactional
    public Lottery saveOrUpdate(Lottery lottery){
        Lottery instance = lotteryDAO.merge(lottery);
        LOG.debug("新增奖品成功"+instance);
        return lottery;
    }

    @Transactional
    public void removeActivity(Lottery lottery) {
        lotteryDAO.delete(lottery);
        LOG.debug("删除奖品成功");
    }

    private final Logger LOG = LoggerFactory.getLogger(getClass());

    public Lottery findById(Integer integer) {
        return  lotteryDAO.findById(integer);
    }

    public List<Lottery> searchAllByPage(SearchParameter<Lottery> parameter) {
        return lotteryDAO.searchAllByPage(parameter);
    }

    public List findLotteryVoAll(){
        return lotteryDAO.findLotteryVoAll();
    }

    public List<Lottery> findLotteryByUserId(Integer userId){
        return lotteryDAO.findLotteryByUserId(userId);
    }

}
